@layout("/common/_container.html"){
<style>
    .leftInfo li{
    list-style:none;
    padding:12px 5px 10px 5px;
}      
.leftInfo{
    position: absolute;
    left: -50px;
    top: 220px;
}
.totalcount{
    background-color: #9999991c
}
.fr{
    float: right;
    margin-right: 5px;
}
.ml5{
   /* margin-left: 5px; */
}
td input{
    width: 100%
}
.form-ahead{
   overflow: hidden;
   margin-bottom: 5px;
}
.head-title-h{
    text-align: center;
    margin-bottom: 10px;
}
.RecYear-div{
    float:right
}
.form-group-block{
    padding: 5px;
    border: 1px solid #ccc
}
li{
    list-style: none;
}
.help-block{
    color:#a94442
}
</style>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="head-title-h">
                <h2>节约用水量年报</h2>
            </div>
            <form class="myform" action="" id="form2">
                <!-- 表头 -->
                <div class="form-ahead">
                    <div class="col-sm-4">
                        <label class="col-sm-12 col-form-label" for="">填表单位名称（盖章）：</label>
                    </div>
                    <div class="col-sm-2 RecYear-div">
                        <label for="RecYear" class="col-sm-4 col-form-label" title="必填项"><i style="color:red">*</i>年份：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control  col-sm-2" name="RecYear" id="RecYear" title=""
                                placeholder="">
                        </div>
                    </div>
                </div>
                <form class="" action="">
                    <div class="form-group row form-group-block">
                        <div class="col-sm-12">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th scope="col">项目</th>
                                        <th scope="col">代码</th>
                                        <th scope="col">年节水总量（万立方米）</th>
                                        <th scope="col">工业</th>
                                        <th scope="col">自取地表水</th>
                                        <th scope="col" title="计算公式：节水器具普及率=节水器具个数/调查器具总数">自备井</th>
                                        <th scope="col">公共供水</th>
                                    </tr>
                                    <tr>
                                        <th scope="col">甲</th>
                                        <th scope="col">乙</th>
                                        <th scope="col">1</th>
                                        <th scope="col">2</th>
                                        <th scope="col">3</th>
                                        <th scope="col">4</th>
                                        <th scope="col">5</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="totalcount">
                                        <th scope="row"title="必填项"><i style="color:red">*</i>合计</th>
                                        <td>01</td>
                                        <td><input name="IndustrySum"></td>
                                        <td><input name="RecycleSum"></td>
                                        <td><input name="SurfaceWater"></td>
                                        <td><input name="GroundWater"></td>
                                        <td><input name="TrapWater"></td>
                                    </tr>
                                    <br>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <label class="col-sm-4 col-form-label" for="Reporter">统计负责人：</label>
                        <div class="col-sm-8">
                            <input type="text" name="Reporter" id="Reporter" value="">
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <label class="col-sm-4 col-form-label" for="Operater"  title="可在“个人资料”进行修改">填表人：</label>
                        <div class="col-sm-8">
                            <input type="text" name="Operater" id="Operater" value="${Operater}" title="可在“个人资料”进行修改" placeholder=""
                                disabled="disabled">
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <label class="col-sm-4 col-form-label" for="Phone"  title="可在“个人资料”进行修改">联系电话：</label>
                        <div class="col-sm-8">
                            <input type="text" name="phone" id="Phone" value="${phone}" value="" title="可在“个人资料”进行修改"
                                placeholder="" disabled="disabled">
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <label class="col-sm-4 col-form-label" for="Ts">报出日期：</label>
                        <div class="col-sm-8">
                            <input type="text" name="ts" id="Ts" value="${Ts}" placeholder="" disabled="disabled">
                        </div>
                    </div>
                </form>
                </br>
                </br>
                </br>
                </br>
                <button type="button" id="saveform" class="btn btn-primary fr">保存</button>
                <button type="button" id="exportform" class="btn btn-primary fr">导出</button>
                <button type="button" id="preview" class="btn btn-primary fr">预览</button>
                <a id='export_a' href=''></a>
        </div>
    </div>
    <!-- 说明文本 -->
    <div>

        <ul>
            <li><strong>说明:</strong></li>
            <li>1.统计范围：纳入统计范围的市、区自备水用水户及各区公共供水用水单位 </li>
            <li>2.报送单位：各用水户</li>
            <li>3.报送时间及方式：每年1月30日前报送，加盖公章的纸介质报表通过传真或扫描后报送到各区节约用水办公室。</li>
            <li>4.自取水表水、自备井、公共供水指各水源供水相应节水量，工业指年节水总量中工业部分节水量。</li>
            

            <br>
            <br>

            <li><strong>指标解释：</strong></li>
            <li>1.节水技改项目节水量取自于节水技改措施年报；</li>
            <li>2.推广节水器具节水量=新装节水型水龙头个数*单位节水型水龙头节水量+新装节水型便器
                水箱个数*单位节水型便器水箱节水量+新装节水型淋浴器个数*单位节水型淋浴器节水量。
                (1)单位水龙头节水量:1.9立方米/个.年(2)单位便器水箱节水量7.56立方米/套.年(3)单位淋
                浴器节水量7.56立方米/个.年 </li>
            <li>3.降低自来水管网漏失节水量指用水单位进行管网改造，降低管网漏失率所节
                约的水量； </li>
            <li> 4.压缩用水计划等综合管理措施指本年度所减少的实际用水总量，扣减新增技改措施节水
                量、新增使用市政中水、新增使用再生水及降低自来水管网漏失节水量； </li>
            <li>5.新增使用建筑中水取自于节水技改措施年报； </li>
            <li>
                6.新增使用市政中水指本年度新增的市政中水利用量；</li>

        </ul>

    </div>

</div>
<script>
      $(document).keydown(function(event){
          switch(event.keyCode){
             case 13:return false; 
             }
      });
    //纵列
    var totalcountStr = ""

    var countList = ["02", "03", "04", "05", "06", "07", "08", "09"]
    var textList=["技改等措施节水量小计","1.节水技改项目","2.推广节水器具","3.降低自来水管网漏失节水量","4.压缩用水计划等综合管理措施","增加使用再生水及中水小计","5.新增使用建筑中水","6.新增使用市政中水",]
    for (var i in countList) {
        totalcountStr = totalcountStr + '<tr>' +
            '<th scope="row">' + textList[i] + '</th>' +
            // '<td>' + textList[i] + '</td>' +
            '<td>' + countList[i] + '</td>' +
            '<td><input name="IndustrySum"></td>' +
            '<td><input name="RecycleSum"></td>' +
            '<td><input name="SurfaceWater"></td>' +
            '<td><input name="GroundWater"></td>' +
            '<td><input name="TrapWater"></td>' +
            '</tr>'
    }
    $(".totalcount").after(totalcountStr)
    //saveform
    //定义serializeObject方法，序列化表单
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

    //表单验证及提交
    $(function () {
        $("#form2").bootstrapValidator({
            live: 'enabled', //验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            excluded: [':disabled', ':hidden', ':not(:visible)'], //排除无需验证的控件，比如被禁用的或者被隐藏的
            fields: {
                RecYear: {
                    validators: {
                        notEmpty: { //检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: { //正则验证
                            regexp: /^\d{4}$/,
                            message: '请输入四位纯数字'
                        }
                    }
                },
                Reporter: {
                    validators: {
                        notEmpty: { //检测非空,radio也可用
                            message: '必填项'
                        },
                        stringLength: { //检测长度
                            min: 0,
                            max: 10,
                            message: '字符长度必须在0-10之间'
                        },
                    }
                },
                IndustrySum: {
                    validators: {
                        regexp: { //正则验证
                            regexp: /^[0-9]*$/,
                            message: '请输入纯数字'
                        },
                        stringLength: { //检测长度
                            min: 0,
                            max: 11,
                            message: '字符长度必须在0-11之间'
                        },
                    }
                },
                RecycleSum: {

                },
                TrapWater: {
                    validators: {
                        regexp: { //正则验证
                            regexp: /^[0-9]*$/,
                            message: '请输入纯数字'
                        },
                        stringLength: { //检测长度
                            min: 0,
                            max: 12,
                            message: '字符长度必须在0-12之间'
                        },
                    }
                },
                SurfaceWater: {
                    validators: {
                        regexp: { //正则验证
                            regexp: /^[0-9]*$/,
                            message: '请输入纯数字'
                        },
                        stringLength: { //检测长度
                            min: 0,
                            max: 12,
                            message: '字符长度必须在0-12之间'
                        },
                    }
                },
                GroundWater: {
                    validators: {
                        regexp: { //正则验证
                            regexp: /^[0-9]*$/,
                            message: '请输入纯数字'
                        },
                        stringLength: { //检测长度
                            min: 0,
                            max: 12,
                            message: '字符长度必须在0-12之间'
                        },
                    }
                }
            }
        })
        //exportform 导出
        $(document).on("click", "#exportform", function () {
            $("#export_a").attr("href", Feng.ctxPath + '/swyreport/dlExcell')
            $("#export_a")[0].click()
        })
        //点击提交
        $("#saveform").click(function () { //非submit按钮点击后进行验证，如果是submit则无需此句直接验证
            $("#form2").bootstrapValidator('validate'); //提交验证
            if ($("#form2").data('bootstrapValidator').isValid()) { //获取验证结果，如果成功，执行下面代码
                var form = $(".ibox .myform").serializeObject();
                var formcorrect = []
                formlenth = [1, 2, 3, 4, 5, 6, 7, 8, 9]
                for (var i in formlenth) {
                    formcorrect.push({
                        GroundWater: form["GroundWater"][i],
                        IndustrySum: form["IndustrySum"][i],
                        RecycleSum: form["RecycleSum"][i],
                        SurfaceWater: form["SurfaceWater"][i],
                        TrapWater: form["TrapWater"][i],
                        RecYear: form["RecYear"],
                        Reporter: form["Reporter"],
                    })
                }
                console.log(formcorrect)
                var ajax = new $ax(Feng.ctxPath + '/swyreport/pushMsg', function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                        } else {
                            Feng.error(data.msg);
                        }
                }, function (data) {
                    Feng.error("请求失败!" + data.msg + "!");
                });
                ajax.set("json", JSON.stringify(formcorrect));
                ajax.start();
            }
            else{
            //解决table校验提示重复问题
            Feng.error("表单有漏填或填写格式错误");//获取验证结果，失败
            }
        });
    })
    $(document).on("click", "#preview", function () {
        window.open(Feng.ctxPath + '/swyreport/showPDF', "_blank",
            "top=200,left=200,height=600,width=800,status=yes,toolbar=1,menubar=no,location=no,scrollbars=yes"
        );
    })
</script>
<script src="${ctxPath}/static/modular/fsjs/swyreport/swyreport.js"></script>
<script>
    //返回的数据渲染
    var ajax = new $ax(Feng.ctxPath + '/swyreport/getTemp', function (data) {
        // Feng.success("请求成功!");
        console.log(data)
        for (var i = 0; i < data.length; i++) {
            $($("input[name=IndustrySum]")[i]).attr("value", data[i].industrySum)
            $($("input[name=RecycleSum]")[i]).attr("value", data[i].recycleSum)
            $($("input[name=SurfaceWater]")[i]).attr("value", data[i].surfaceWater)
            $($("input[name=GroundWater]")[i]).attr("value", data[i].groundWater)
            $($("input[name=TrapWater]")[i]).attr("value", data[i].trapWater)
            $($("input[name=RecycleSum]")[i]).attr("value", data[i].recycleSum)
            $($("input[name=RecycleSum]")[i]).attr("value", data[i].recycleSum)
        }
        // $("#Reporter").attr("value",data[0].reporter)
        $("#RecYear").attr("value", data[0].recYear)

    }, function (data) {
        // Feng.error("请求失败!");
    });
    ajax.start();

    //合计 
    var countall = parseInt($("input[name=SurfaceWater]").val()) + parseInt($("input[name=GroundWater]").val()) +
        parseInt($("input[name=TrapWater]").val())
    console.log(countall)
    // $("input[name=IndustrySum]:first").attr("value", countall)

    $(document).on("change", ".totalcount input", function () {
        var countall = parseInt($("input[name=SurfaceWater]").val()) + parseInt($("input[name=GroundWater]").val()) +
            parseInt($("input[name=TrapWater]").val())
        $("input[name=IndustrySum]:first").attr("value", countall)
    })
</script>
@}